package com.api.department.getdepartmentsforuser;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.test.context.ContextConfiguration;
import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

import com.api.test.AbstractApiTest;
import com.zyncro.api.IDepartmentApiService;
import com.zyncro.api.exceptions.ZyncroApiException;
import com.zyncro.api.model.DepartmentApi;
import com.zyncro.api.model.DepartmentFilterApiType;
import com.zyncro.api.model.PagedItemsResultApi;

@ContextConfiguration(locations = "classpath:/department/departments-toget.xml")
public class GetDepartmentsForUser extends AbstractApiTest {

	@Value("#{user_contact.appId}")
	private String userUrn;

	@Value("#{user_contact.password}")
	private String userPassword;

	@Value("#{user_contact.appId}")
	private String iduser;

	@Value("#{user_contact.totalDepartments}")
	private int totalDepartments;

	@Value("#{user_contact.totalMemberDepartments}")
	private int totalMemberDepartments;

	@Value("#{user_contact.totalFollowedDepartments}")
	private int totalFollowedDepartments;

	@BeforeClass
	protected void loginUser() throws Exception {

		getApi().login(userUrn, userPassword);
	}

	@Test
	public void testGetDepartmentsAll() throws ZyncroApiException {

		int pageNumber = 0;
		int itemsPerPage = 0;
		DepartmentFilterApiType departmentFilter = null;
		String startsWith = null;

		PagedItemsResultApi<DepartmentApi> result = getApi().getService(IDepartmentApiService.class).getDepartmentsForUser(iduser,
				pageNumber, itemsPerPage, departmentFilter, startsWith, null, null);

		Assert.assertEquals(result.getTotalItems(), totalDepartments, "Total departments");
	}

	@Test
	public void testGetDepartmentsMember() throws ZyncroApiException {

		int pageNumber = 0;
		int itemsPerPage = 0;
		DepartmentFilterApiType departmentFilter = DepartmentFilterApiType.JUST_MEMBER;
		String startsWith = null;

		PagedItemsResultApi<DepartmentApi> result = getApi().getService(IDepartmentApiService.class).getDepartmentsForUser(iduser,
				pageNumber, itemsPerPage, departmentFilter, startsWith, null, null);

		Assert.assertEquals(result.getTotalItems(), totalMemberDepartments, "Total member departments");
	}

	@Test
	public void testGetDepartmentsFollower() throws ZyncroApiException {

		int pageNumber = 0;
		int itemsPerPage = 0;
		DepartmentFilterApiType departmentFilter = DepartmentFilterApiType.JUST_FOLLOWER;
		String startsWith = null;

		PagedItemsResultApi<DepartmentApi> result = getApi().getService(IDepartmentApiService.class).getDepartmentsForUser(iduser,
				pageNumber, itemsPerPage, departmentFilter, startsWith, null, null);

		Assert.assertEquals(result.getTotalItems(), totalFollowedDepartments, "Total followed departments");
	}
}
